////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   ERROR_MSG_LABEL
// AUTHOR           :   Victor Zheng 
// DATE CREATE      :   2006/01/12
// DESCRIPTION      :   a PK file for the function, ERROR_MSG_LABEL
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/01/12   Victor Zheng    1.0                 source is created.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.admin.errorMsg.util;

import java.util.Map;

import com.erp.app.admin.errorMsg.pk.ErrorMsgLabelPk;
import com.erp.app.admin.errorMsg.vo.ErrorMsgLabelVo;
import com.erp.app.common.ProjectConstants;
import com.erp.app.common.util.ProjectCommonUtil;

public class ErrorMsgUtil extends ErrorMsgLabelPk {

    private Map errMsgMap;

    public ErrorMsgUtil() {
        this("", "", "", null);
    }

    public ErrorMsgUtil(String companyCode, String menuId, String langCode, Map errMsgMap) {
        super(companyCode, ProjectConstants.DBMENU_GENERAL_MENU, menuId, "", langCode);
        this.setErrMsgMap(errMsgMap);
    }

    public void setCompanyCode(String companyCode) {
        this.companyCode = companyCode;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public void setLangCode(String langCode) {
        this.langCode = langCode;
    }

    public void setMenuId(String menuId) {
        this.menuId = menuId;
    }

    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }

    public Map getErrMsgMap() {
        return errMsgMap;
    }

    public void setErrMsgMap(Map errorMsgMap) {
        ProjectCommonUtil.assertTrue(errorMsgMap != null, "errorMsgMap should not be null");
        this.errMsgMap = errorMsgMap;
    }

    public ErrorMsgLabelVo getErrorMsgLabel(ErrorMsgLabelPk key) {
        return (ErrorMsgLabelVo) this.getErrMsgMap().get(key);
    }

    public String getErrorMsgObjectWebLabel(ErrorMsgLabelPk key) {
        ErrorMsgLabelVo label = this.getErrorMsgLabel(key);
        return (label != null) ? label.getObjectWebLabel() : key.getObjectId();
    }

    public String getErrorMsgObjectWebLabel(String objectId) {
        return this.getErrorMsgObjectWebLabel(this.makeErrorMsgLabelPk(this.getGroupId(),
                objectId));
    }

    public ErrorMsgLabelPk makeErrorMsgLabelPk(String groupId, String objectId) {
        return new ErrorMsgLabelPk(this.getCompanyCode(), groupId, this
                .getMenuId(), objectId, this.getLangCode());
    }

    public ErrorMsgLabelPk makeErrorMsgLabelPk(String objectId) {
        return new ErrorMsgLabelPk(this.getCompanyCode(),
                ProjectConstants.DBMENU_GENERAL_MENU, this.getMenuId(),
                objectId, this.getLangCode());
    }

}
